package com.lyw.controller;

import com.lyw.entity.Student;
import com.lyw.entity.User;
import com.lyw.exception.UserTooManyException;
import com.lyw.mapper.StudentMapper;
import com.lyw.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class TablesController {

  @Autowired
  UserMapper userMapper;

  @Autowired
  StudentMapper studentMapper;

  @GetMapping("/tables.html")
  public String table(Model model) {
    List<User> users = userMapper.findUsers();

    /*if (users.size() > 3)
      throw new UserTooManyException("用户数量太多啦！！！");*/

    model.addAttribute("users", users);
    return "tables";
  }

  @ResponseBody
  @GetMapping("/students")
  public List<Student> students() {
    return studentMapper.findStudents();
  }

  @GetMapping("/editable_table.html")
  public String dynamic_table() {
    return "editable_table";
  }
}
